package com.EpidemicPrevention.controller;

import com.EpidemicPrevention.pojo.Item_info;
import com.EpidemicPrevention.service.Item_infoServiceImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;




@Controller
@RequestMapping("/Item_infoController")
public class Item_infoController {

    @Autowired
    private Item_infoServiceImpl item_infoService;
    @GetMapping("/addItem_info")
    @ResponseBody
    @CrossOrigin
    public JSON addItem_info(Item_info item_info) {
        return item_infoService.addItem_info (item_info);
    }


    @GetMapping("/updataItem_info")
    @ResponseBody
    @CrossOrigin
    public  JSON updataItem_info(Item_info item_info){
        return item_infoService. updateItem_info (item_info);
    }

    /**
     * 删除用户
     *
     * @param id
     * @return
     */
    @GetMapping("/deleteItem_info")
    @ResponseBody
    @CrossOrigin
    public JSON deleteEnrolled(int id) {
        return item_infoService.deleteItem_info (id);
    }




    @GetMapping("/queryItem_info")
    @ResponseBody
    @CrossOrigin
    public JSON queryItem_info(@RequestParam("page") int page, @RequestParam("limit") int limit) {
        JSONObject json = new JSONObject();
        int page1 = page - 1;
        int page2 = page1 * limit;
        json.put("code", 1);
        json.put("msg", "");
        json.put("count", item_infoService.queryItem_info (0, 100,null).size());
        json.put("data",item_infoService.queryItem_info(page2, limit,null));
        return json;
    }



    /**
     * 关键字查看情绪小妙招
     * @param page
     * @param limit
     * @param Keyword
     * @return
     */
    @GetMapping("/selectWhereItem_info")
    @ResponseBody
    @CrossOrigin
    public JSON selectWhereItem_info(@RequestParam("page")int page,@RequestParam("limit")int limit,@RequestParam("Keyword")String Keyword) {
        JSONObject json = new JSONObject();
        int page1 = page - 1;
        int page2 = page1 * limit;
        json.put("code", 1);
        json.put("msg", "查询成功");
        json.put("count", item_infoService.queryItem_info(0, 100000, Keyword).size());
        json.put("data", item_infoService.queryItem_info(page2, limit, Keyword));
        return json;
    }


}










